﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Formatting.Json;
using Exceptionless;

namespace SerilogTest
{

  class Test
  {
    private readonly ILogger<Test> logger;

    public Test(ILogger<Test> logger)
    {
      this.logger = logger;
    }
    public void Test1()
    {
      logger.LogDebug("1233");
      logger.LogInformation("1233");
      logger.LogError("1233");
      logger.LogWarning("1233");
      logger.LogWarning("新增一个People：{@person}",new People { Age=19,Name="yezi",Email="1562@outlook.com"});//通过占位符将对象以Json格式输出
    }
  }
  class People
  {
    public string Name { get; set; }
    public int Age { get; set; }
    public string Email { get; set; }
  }
  internal class Program
  {
    
    static void Main(string[] args)
    {
      ExceptionlessClient.Default.Startup("PfHLXHOVnyjusqDz03JTfo65Ro91clhubskOUfhL");
      ServiceCollection services = new ServiceCollection();
      //services.AddExceptionless("PfHLXHOVnyjusqDz03JTfo65Ro91clhubskOUfhL");
     
      //结构化日志
      services.AddLogging(logBuilder =>
      {
        Log.Logger = new LoggerConfiguration()
        .MinimumLevel.Debug()
        .Enrich.FromLogContext()
        .WriteTo.Console(new JsonFormatter())
        .WriteTo.Exceptionless()
        .CreateLogger();
        logBuilder.AddSerilog();
      });
     

      services.AddScoped<Test>();

      using (var sp=services.BuildServiceProvider())
      {
        var t1 = sp.GetRequiredService<Test>();
        t1.Test1();
      }


      Console.ReadLine();
    }
  }
}
